<?php
include 'db.php';

$facilities = array();

//extract the shit from the form
foreach( $_POST as $field => $value )
{
	if( preg_match( '/fac_(\d+)_(\w+)/', $field, $matched_ids ) )
	{
		$facilities[ $matched_ids[1] ][ $matched_ids[2] ] = $value;
	}
}

//now we need to go through all the facilities and modify them
$update_facility->bind_param( 'ddddi', $fac_mm, $fac_tm, $fac_ic, $fac_phc, $fac_id );
foreach( $facilities as $fac => $data )
{
	$fac_id = $fac;
	$fac_mm = $data[ 'mm' ];
	$fac_tm = $data[ 'tm' ];
	$fac_ic = $data[ 'ic' ];
	$fac_phc = $data[ 'phc' ];

	if( $data[ 'upd' ] == 'on' )
	{
		$update_facility->execute();
	}
}
$update_facility->close();

include 'view_facilities.php';

?>